<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: Cruise <jiangyu@hrbjjhh.com><jiangyu@hrbjjhh.com>
// +----------------------------------------------------------------------------

namespace Admin\Model;
use Admin\Model\BaseModel;
/**
 * @todo 班车点模型
 * @author Cruise <jiangyu@hrbjjhh.com> <jiangyu@hrbjjhh.com>
 */
class ServiceBusPointModel extends BaseModel {

    /* 自动验证规则 */
    protected $_validate = array(
    	array('province_id', 'checkId', '请选择省份', self::MUST_VALIDATE, 'callback', self::MODEL_INSERT),
    	array('city_id', 'checkId', '请选择城市', self::MUST_VALIDATE, 'callback', self::MODEL_INSERT),
    	array('ward_id', 'checkId', '请选择行政区', self::MUST_VALIDATE, 'callback', self::MODEL_INSERT),
        array('bus_point_name', 'require', '班车点不能为空', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
    	//array('bus_point_addres', 'require', '班车地址不能为空', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
    	array('bus_point_name', '1,30', '班车点长度不能超过30个字符', self::MUST_VALIDATE, 'length', self::MODEL_BOTH),
    );

    /* 自动完成规则 */
    protected $_auto = array(
    	array('create_time', NOW_TIME, self::MODEL_INSERT),
    	array('update_time', NOW_TIME, self::MODEL_UPDATE),
    	//array('province_id','1',self::MODEL_INSERT),
    	array('status', '1', self::MODEL_INSERT),
    );

    /**
     * @todo 班车点详情
     * @param int $bus_point_id 班车点id
     * @param string $field 查询字段
     * @return false|array
     * @author Cruise <jiangyu@hrbjjhh.com>
     */
    public function ServiceBusPointShow($bus_point_id = 0,$field = ''){
    	//获取数据
    	$bus_point_id = (int)$bus_point_id;
    	if($bus_point_id == 0){
    		$this->error = '请正确操作';
    		return false;
    	}
    	$map = array();//初始化查询条件
    	//查询条件
    	$map['bus_point_id'] = $bus_point_id;
    	$map['status'] = array('gt',-1);
    	//返回值
    	return $this->where($map)->field($field)->find();
    }
       
    /**
     * @todo 检测省市区联动是否成立
     * @param  string $id 省市区id
     * @return boolean     ture - id成立，false - id无效
     */
    protected function checkId($id){
    	if($id == 0 || $id == ''){
    		return false;
    	}else{
    		return true;
    	}
    }
    
    /**
     * @todo 返回主键
     * @see \Think\Model::getPk()
     * @author PHP@妖孽 <mashengjie@hrbjjhh.com>
     */
    public function getPk(){
    	return 'bus_point_id';
    }
}
